package com.zcp.flowlayoutdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private String[] mVals = new String[]
            {
                    "hello", "你好", "早上好啊", "非常不好", "很生气", "welcome",
                    "早上好,中午好", "下午好,好好好", "所发生的发生的顺风使帆",
                    "dedsfdfdrfer", "撒旦撒S阿苏伟大的丰富"
            };
    private FlowLayou mFlowLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //动态添加控件
        mFlowLayout = (FlowLayou) findViewById(R.id.flowLayout);
        initData();

    }

    public void initData() {
        for (int i = 0; i < mVals.length; i++) {
            Button btn = new Button(this);
            ViewGroup.MarginLayoutParams mlayoutParams
                    = new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT);
            btn.setText(mVals[i]);
            mFlowLayout.addView(btn, mlayoutParams);
        }
    }
}
